﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;

namespace Microhard.Framework.MVCHelper
{
    public class DropDownListValidaitonAttribute : ValidationAttribute
    {
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            var rtn = new ValidationResult(this.ErrorMessage);
            if (value == null)
                return rtn;

            int vle = 0;
            if (int.TryParse(value.ToString(), out vle))
            {
                if (vle > -1)
                {
                    rtn = ValidationResult.Success;
                }
            }
            return rtn;
        }
    }
}
